import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../color.dart';

Widget moneyInputWidget({ValueChanged<String>? onTap,ValueChanged<String>? deleteOnTap,ValueChanged<String>? confirmOnTap}) {
  return Material(
    child: Container(
      padding: EdgeInsets.all(3.w),
      color: ColorManager.colorF7F7F7,
      width: ScreenUtil().screenWidth,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          IntrinsicHeight(
            child: Row(
              children: [
                Expanded(
                  flex: 3,
                  child: Container(
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Row(
                          children: [
                            Expanded(child: numberItem("1",onTap: onTap),flex: 1,),
                            Expanded(child: numberItem("2",onTap: onTap),flex: 1,),
                            Expanded(child: numberItem("3",onTap: onTap),flex: 1,),
                          ],
                        ),
                        Row(
                          children: [
                            Expanded(child: numberItem("4",onTap: onTap),flex: 1,),
                            Expanded(child: numberItem("5",onTap: onTap),flex: 1,),
                            Expanded(child: numberItem("6",onTap: onTap),flex: 1,),
                          ],
                        ),
                        Row(
                          children: [
                            Expanded(child: numberItem("7",onTap: onTap),flex: 1,),
                            Expanded(child: numberItem("8",onTap: onTap),flex: 1,),
                            Expanded(child: numberItem("9",onTap: onTap),flex: 1,),
                          ],
                        ),
                        Row(
                          children: [
                            Expanded(child: numberItem("0",onTap: onTap),flex: 2,),
                            Expanded(child: numberItem(".",onTap: onTap),flex: 1,),
                          ],
                        )
                      ],
                    ),
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Container(
                    child: Column(
                      children: [
                        Expanded(child: numberItem("0",child: Image.asset("packages/hopson_utils/images/icon_key_board_delete.png", width: 18.w, height: 16.w,),onTap: deleteOnTap),flex: 1,),
                        Expanded(child: numberItem("确定",fontSize: 15.w,backgroudColor: ColorManager.colorF65247,lightingBackgroudColor: ColorManager.colorF65247,onTap: confirmOnTap),flex: 3,),
                      ],
                    ),
                  ),
                )
              ],
            ),
          ),
          SizedBox(height: ScreenUtil().bottomBarHeight,)
        ],
      ),
    ),
  );
}

Widget numberItem(String number,{Color? backgroudColor,Color? lightingBackgroudColor,Widget? child,ValueChanged<String>? onTap,double? fontSize}) {
  bool tapUp = true;
  return StatefulBuilder(
    builder: (BuildContext context, StateSetter setState) {
      return GestureDetector(
        onTap: () {
          if (onTap != null) {
            onTap(number);
          }
        },
        onTapUp: (TapUpDetails details) {
          setState(() {
            tapUp = true;
          });
        },
        onTapDown: (TapDownDetails details) {
          HapticFeedback.mediumImpact();
          setState(() {
            tapUp = false;
          });
        },
        onTapCancel: () {
          setState(() {
            tapUp = true;
          });
        },
        child: Container(
          height: tapUp?44.w:38.w,
          margin: EdgeInsets.all(tapUp?3.w:6.w),
          decoration: BoxDecoration(
            color: tapUp?(backgroudColor ?? ColorManager.colorFFFFFF):(lightingBackgroudColor ?? ColorManager.colorEDEDED),
            borderRadius: BorderRadiusDirectional.circular(2.w),
          ),
          child: Center(
            child: child??Text(
              number,
              style: TextStyle(
                color: backgroudColor==null?ColorManager.color2A2A2A:ColorManager.colorFFFFFF,
                fontSize: fontSize ?? 20.w,
                fontWeight: FontWeight.w700,
              ),
            ),
          ),
        ),
      );
    },
  );
}
